package com.ksp.api.quartz;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface QuartzMapper {
	
	String QRY_TBL_ROW = ""
			+ "SELECT TABLE_NAME AS TBL_NAM, "
			+ "       TABLE_ROWS AS TBL_ROW"
			+ "  FROM INFORMATION_SCHEMA.TABLES"
			+ " WHERE TABLE_SCHEMA = #{SCH_NAM}"
			+ "   AND TABLE_NAME LIKE CONCAT(#{TBL_NAM}, '%');"
			+ "";

	String CRT_TBL_TSK = ""
			+ "use kspt;"
			+ "DROP TABLE IF EXISTS `ksp_ksp_tsk`;"
			+ "DROP TABLE IF EXISTS `ksp_ksp_tsk_${TBL_SEQ}`;"
			+ "CREATE TABLE `ksp_ksp_tsk_${TBL_SEQ}` ("
			+ "  `KSP_TCH_IDN` CHAR(10) NOT NULL COMMENT '任务id',"
			+ "  `KSP_KSP_TTL` CHAR(200) NOT NULL DEFAULT '问题' COMMENT '任务主题',"
			+ "  `KSP_KSP_CON` longtext NULL COMMENT '任务详细说明',"
			+ "  `KSP_IMP_DEG` CHAR(1) NOT NULL DEFAULT 0 COMMENT '任务重要级别（1-低，2-中，3-高）',"
			+ "  `KSP_DEA_USR` CHAR(20) NULL COMMENT '任务处理人员',"
			+ "  `KSP_DEA_UNM` CHAR(10) NULL COMMENT '任务处理人员姓名',"
			+ "  `KSP_TSK_STS` CHAR(1) NOT NULL DEFAULT 'W' COMMENT '任务处理状态（W-待处理,P-处理中,S-已完成,F-已驳回）',"
			+ "  `KSP_TSK_TYP` CHAR(1) NOT NULL DEFAULT '4' COMMENT '任务类别（1-工作平台，2-自动发布工具，3-微服务，4-其他）',"
			+ "  `KSP_QUA_USR` CHAR(20) NULL DEFAULT '1000000000' COMMENT '问题反馈人员',"
			+ "  `KSP_QUA_UNM` CHAR(10) NULL COMMENT '问题反馈人员姓名',"
			+ "  `KSP_QUA_DBG` CHAR(26) NULL COMMENT '问题提出时间',"
			+ "  `KSP_MNT_DAT` CHAR(26) NULL COMMENT '最后修改时间',"
			+ "  `KSP_SPC_RMK` longtext NULL COMMENT '备注信息',"
			+ "  `KSP_DEL_FLG` CHAR(200) DEFAULT 'N' COMMENT '任务删除标识（Y-已删除，N-未删除）',"
			+ "  PRIMARY KEY (`KSP_TCH_IDN`),"
			+ "  UNIQUE INDEX `KSP_TCH_IDN_UNIQUE` (`KSP_TCH_IDN` ASC)"
			+ "  )DEFAULT CHARSET=utf8 COMMENT = '任务信息表' ENGINE=MyISAM;"
			+ "  ";
	
	String REC_UNI_TSK = ""
			+ "use kspt;"
			+ "CREATE TABLE `ksp_ksp_tsk` ("
			+ "  `KSP_TCH_IDN` CHAR(10) NOT NULL COMMENT '任务id',"
			+ "  `KSP_KSP_TTL` CHAR(200) NOT NULL DEFAULT '问题' COMMENT '任务主题',"
			+ "  `KSP_KSP_CON` longtext NULL COMMENT '任务详细说明',"
			+ "  `KSP_IMP_DEG` CHAR(1) NOT NULL DEFAULT 0 COMMENT '任务重要级别（1-低，2-中，3-高）',"
			+ "  `KSP_DEA_USR` CHAR(20) NULL COMMENT '任务处理人员',"
			+ "  `KSP_DEA_UNM` CHAR(10) NULL COMMENT '任务处理人员姓名',"
			+ "  `KSP_TSK_STS` CHAR(1) NOT NULL DEFAULT 'W' COMMENT '任务处理状态（W-待处理,P-处理中,S-已完成,F-已驳回）',"
			+ "  `KSP_TSK_TYP` CHAR(1) NOT NULL DEFAULT '4' COMMENT '任务类别（1-工作平台，2-自动发布工具，3-微服务，4-其他）',"
			+ "  `KSP_QUA_USR` CHAR(20) NULL DEFAULT '1000000000' COMMENT '问题反馈人员',"
			+ "  `KSP_QUA_UNM` CHAR(10) NULL COMMENT '问题反馈人员姓名',"
			+ "  `KSP_QUA_DBG` CHAR(26) NULL COMMENT '问题提出时间',"
			+ "  `KSP_MNT_DAT` CHAR(26) NULL COMMENT '最后修改时间',"
			+ "  `KSP_SPC_RMK` longtext NULL COMMENT '备注信息',"
			+ "  `KSP_DEL_FLG` CHAR(200) DEFAULT 'N' COMMENT '任务删除标识（Y-已删除，N-未删除）',"
			+ "  PRIMARY KEY (`KSP_TCH_IDN`),"
			+ "  UNIQUE INDEX `KSP_TCH_IDN_UNIQUE` (`KSP_TCH_IDN` ASC)"
			+ "  )DEFAULT CHARSET=utf8 COMMENT='任务信息表' INSERT_METHOD=LAST"
			+ "  ENGINE=MERGE UNION(${TBL_LST});"
			+ "";
	
	@Select(QRY_TBL_ROW)
	List<Map<String, Object>> qryTblRow(Map<String, Object> pPamMap);
	
	@Insert(CRT_TBL_TSK)
	int crtTblTsk(Map<String, Object> pPamMap);
	
	@Insert(REC_UNI_TSK)
	int recUniTsk(Map<String, Object> pPamMap);
	
}
